/******************************************************************************\
 *                                                                            *
 *                          Craftmesh Controller                              *
 *                   Flavio Bertini fl.bertini@gmail.com                      *
 *                                                                            *
 *                                                                            *
\******************************************************************************/


#if !defined(__Craftmesh_controller_h__)
#define __Craftmesh_controller_h__


#include <GL/freeglut.h>
#include "Leap.h"
#include "Const.h"
#include "Math.h"
#include "Craftmesh_model.h"
#include "Craftmesh_viewer.h"


using namespace Leap;
using namespace std;


// Struct grasping hand
struct Con_HandController
{
  public:
    Hand       handRef;     // hand reference
    FingerList fingRef;     // fingers refernce
    int        meshRef;     // mesh reference
    int        frameTap;    // useful to avoid repeated tap gesture
    bool       firstFist;   // close hand the first time
    Frame      frameTrans;  // frame translation probability
    int        left_right;  // define if the hand is a left or right hand
    float      selecRadius; // selection sphere radius
    GLfloat    color[3];    // color of the fingers tip
};


// Class Listener
class Con_CraftmeshListener : public Listener
{
  public:
    Con_CraftmeshListener();

    ~Con_CraftmeshListener();

    // function called when an instance of a Listener subclass is added to the controller
    void onInit(const Controller& controller);

    // function called when a connection is established between the controller and the Leap Motion software
    void onConnect(const Controller& controller);

    // function called if the connection is losed for any reason
    void onDisconnect(const Controller& controller);

    // function called if the listener is removed from the controller or the controller is destroyed
    void onExit(const Controller& controller);

    // recover and manage the most recent frame form the Leap
    void onFrame(const Controller& controller);

    void onFocusGained(const Controller& controller);

    void onFocusLost(const Controller& controller);

}; // class CraftmeshListener


#endif // __Craftmesh_controller_h__
